<?php
ob_start();
session_start();
$start = microtime(true);
$inc = '../include';
require_once("$inc/header.php");
/******************************/

echo file_get_contents('../html/register');
require_once('../include/validation.php');

if(isset($_POST['register'])) {
	if(validate_login_name($_POST['login_name']) &&
		validate_password($_POST['pwd1'], $_POST['pwd2']) &&
		validate_email($_POST['email'])) {

			# create user account
			$password = sha1($_POST['pwd1']);
			$user = mysql_real_escape_string($_POST['login_name']);
			$mail = mysql_real_escape_string($_POST['email']);
			$sql = "INSERT INTO users (username, password, mail) VALUES('$user', '$password', '$mail')";

			if(mysql_query($sql)) {
				$headers = 'From: Pokeralyzer <mailer@pokeralyzer.com>';
				mail($mail, 
					"You've been Pokeralyzed", 
					"Hi $user, this mail has been sent to confirm your account on www.pokeralyzer.com",
					$headers
				);
				header('Location: ../account/');
			} else {
				header('Location: ../account/');
			}
		
	} else {
		header('Location: ../account/');
	}
} 

/******************************/
require_once("$inc/right.php");
require_once("$inc/footer.php");
ob_end_flush();
?>

